﻿using System;
using System.Collections;
using System.Windows.Forms;
using ZYCommon;
using System.Threading;
using TextEditor.TextDocument.Document;

namespace TextEditor
{
 
    public abstract class A_Action
    {
        public bool AltKey = false;
        public bool ControlKey = false;
        internal ArrayList Elements = null;
        public Keys HotKey = Keys.None;
        public Keys KeyCode = Keys.None;
        public MouseButtons MouseButton = MouseButtons.None;
        public int MouseX = 0;
        public int MouseY = 0;
        protected ZYTextDocument myOwnerDocument = null;
        public string Param1 = null;
        public string Param2 = null;
        public string Param3 = null;
        public string Param4 = null;
        public string controlText = "";
        internal int SelectLength = -1;
        internal int SelectLength2 = -1;
        internal int SelectStart = -1;
        internal int SelectStart2 = -1;
        public bool ShiftKey = false;
        internal ZYTextElement SingleElement = null;

        protected A_Action()
        {
            
        }

        public abstract string ActionName();

        protected A_Action BaseCloneFrom(A_Action a)
        {
            if ((a != null) && (a != this))
            {
                this.myOwnerDocument = a.OwnerDocument;
                this.HotKey = a.HotKey;
                this.KeyCode = a.KeyCode;
                this.ShiftKey = a.ShiftKey;
                this.ControlKey = a.ControlKey;
                this.AltKey = a.AltKey;
                this.MouseX = a.MouseX;
                this.MouseY = a.MouseY;
                this.MouseButton = a.MouseButton;
                this.Param1 = a.Param1;
                this.Param2 = a.Param2;
                this.Param3 = a.Param3;
                if (a.Elements != null)
                {
                    this.Elements = new ArrayList();
                    this.Elements.AddRange(a.Elements);
                }
                this.SingleElement = a.SingleElement;
                return this;
            }
            return null;
        }

        public virtual bool CanHandleKeyDown()
        {
            return true;
        }

        public virtual int CheckState()
        {
            return -1;
        }

        public virtual A_Action Clone()
        {
            return null;
        }

        public virtual bool Execute()
        {
            return true;
        }

        public virtual string GetText()
        {
            return this.Param1;
        }

        public virtual bool isEnable()
        {
            return true;
        }

        public virtual bool isUndoable()
        {
            return false;
        }

        public virtual bool Redo()
        {
            return this.Execute();
        }

        public bool SetText(string strText)
        {
            this.Param1 = strText;
            return true;
        }

        public virtual bool TestHotKey(Keys vKeyCode, bool vShift, bool vControl, bool vAlt)
        {
            if (this.HotKey == Keys.None)
            {
                return false;
            }
            if (vShift)
            {
                vKeyCode |= Keys.Shift;
            }
            if (vControl)
            {
                vKeyCode |= Keys.Control;
            }
            if (vAlt)
            {
                vKeyCode |= Keys.Alt;
            }
            return (vKeyCode == this.HotKey);
        }

        public   delegate bool  MyDelegate();
        public virtual bool UIExecute()
        { 
            return this.Execute(); 
        }

        public virtual bool Undo()
        {
            return true;
        }

        public virtual string UndoName()
        {
            return null;
        }

        public ZYTextDocument OwnerDocument
        {
            get
            {
                return this.myOwnerDocument;
            }
            set
            {
                this.myOwnerDocument = value;
            }
        }

        public virtual string getStr
        {
            get 
            {
                return "";
            }
        }
    }
}

